/**
 * @param {number[]} answers
 * @return {number}
 */
const numRabbits = function (answers: number[]) {

    if (answers.length === 0) return 0

    answers.sort((a, b) => a - b)

    let same = answers[0]
    let max = same + 1
    let sum = 0
    let sameCount = 1
    for (let i = 1; i < answers.length; i++) {

        if (same === answers[i]) {
            sameCount += 1

            if (sameCount > max) {
                sum += same + 1

                sameCount = 1
            }

        } else {
            sum += same + 1

            same = answers[i]
            sameCount = 1
            max = same + 1
        }
    }

    if (sameCount > 0) {
        sum += same + 1
    }

    return sum

};


console.log(numRabbits(
    [0,0,1]));